package com.qfedu.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qfedu.dao.SysOrderMapper;
import com.qfedu.pojo.SysOrder;
import com.qfedu.pojo.SysUser;
import com.qfedu.service.SysOrderService;
import com.qfedu.vo.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Service
public class SysOrderServiceImpl implements SysOrderService {
    @Autowired
    SysOrderMapper sysOrderMapper;
    @Override
    public BaseResult add(SysOrder sysOrder) {
        sysOrderMapper.add(sysOrder);
        return new BaseResult();
    }

    @Override
    public BaseResult all(Integer page, Integer limit, HttpServletRequest request) {
        SysUser sysUser=(SysUser)request.getSession().getAttribute("user");

         PageHelper.startPage(page, limit);
        List<SysOrder> all = sysOrderMapper.all(sysUser.getId());
        PageInfo pageInfo = new PageInfo(all);
        BaseResult baseResult=new BaseResult();
        baseResult.setInfo(pageInfo);
        baseResult.setCode(1);
        return baseResult;
    }

    @Override
    public BaseResult del(Integer id) {
        sysOrderMapper.del(id);

        return new BaseResult();
    }
}
